#include "debug.h"
#include "initialization.h"
#include "rtx_inc.h"
#include "globals.h"
#include "context.h"
#include "proctables.h"
#include "test_processes.h"
#include "i_processes.h"

/*
 * gcc expects this function to exist
 */
int __main( void )
{
    return 0;
}

/*
 * Entry point, check with m68k-coff-nm
 */
int main( void )
{
	UINT32 stack_start = __end;

	current_process = (PCB*)NULL;

	// Disable interrupts, as we do not want anything interrupted at this point
	asm("move.w #0x2700,%sr");

	setTestInfo();
	setIProcInfo();

	debug_out_string("Program Started!!!!\n\r");
	stack_start = init_memory ();
	debug_out_string("Memory Initialized!!!!\n\r");
	init_interrupts();
	debug_out_string("Interupts Initilized!!!!\n\r");
	init_queues ();

	if(ready_queue.queues[0].head != NULL ) {
		debug_out_string("ERRORR!!!\n\r");
	}
	if(ready_queue.queues[0].tail != NULL ) {
		debug_out_string("ERROR!!!!\n\r");
	}

	debug_out_string("Queues Setup!!!!\n\r");
	init_processes(stack_start);
	debug_out_string("Processes Done!!!!\n\r");

	process_switch();

	// Renable interrupts, as we do not want anything interrupted at this point
	asm("move.w #0x2000,%sr");

	return 0;
}
